package org.gpp.proj1.test;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.gpp.proj1.robot.action.parser.ActionFileParser;
import org.gpp.proj1.robot.action.parser.MalformedActionScriptException;
import org.gpp.proj1.robot.action.step.ActionStep;
import org.gpp.proj1.robot.action.step.ChangeAnimationActionStep;
import org.gpp.proj1.robot.action.step.DelayActionStep;
import org.gpp.proj1.robot.action.step.EmissionActionStep;
import org.gpp.proj1.util.test.JMETestDisplayManager;

import com.jme.util.LoggingSystem;

public class ActionFileParserFacade {
	
	private Map<String, List<ActionStep>> actionsMap;

	public ActionFileParserFacade() {
		// Disabling logging
		LoggingSystem.getLoggingSystem().loggerOn( false );
		
		JMETestDisplayManager.initJME();
		
		this.actionsMap = new HashMap<String, List<ActionStep>>();
	}
	
	public String loadAction(String actionFile) throws MalformedActionScriptException, IOException {
		
		File f = new File(actionFile);
		String actionName = f.getName().substring(0, f.getName().lastIndexOf("."));
		
		this.actionsMap.put(actionName, ActionFileParser.parseFile(actionFile));
				
		return actionName;
	}
	
	public int getActionCount(String action) {
		
		return this.actionsMap.get(action).size();
	}
	
	public String getAnimation(String action, int index) {
		
		return ((ChangeAnimationActionStep)this.actionsMap.get(action).get(index)).getAnimation();
	}
	
	public long getDelay(String action, int index) {
		
		return ((DelayActionStep)this.actionsMap.get(action).get(index)).getMilliseconds();
	}
	
	public String getEmissorName(String action, int index) {
		
		return ((EmissionActionStep)this.actionsMap.get(action).get(index)).getEmissorName();
	}
}